﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PMS.Helper
{
    public class helper
    {
        public static string GetNumber(string headerStr)
        {
            if (string.IsNullOrEmpty(headerStr))
            {
                headerStr = "BH";
            }
            StringBuilder strbuilder = new StringBuilder();
            strbuilder.Append(headerStr);
            strbuilder.Append(DateTime.Now.ToString("yyyyMMddhhmmss"));
            Random rnd = new Random();
            strbuilder.Append(rnd.Next(1000,9999));
            return strbuilder.ToString();
        }
        public static string GetPYCode(string paramChinese)
        {

            StringBuilder strbuilder = new StringBuilder();
            for (int i = 0; i < paramChinese.Length; i++)
            {
                strbuilder.Append(GetLetter(paramChinese.Substring(i,1)));
            }
            return strbuilder.ToString();
            
        }
        protected static string GetLetter(string paramChar)
        {
            long ichar;
            byte[] zw = System.Text.Encoding.Default.GetBytes(paramChar);
            if (zw.Length == 1)
            {
                return paramChar.ToUpper();
            }
            else
            {
                int i1 = (short)zw[0];
                int i2 = (short)zw[1];
                ichar = i1 * 256 + i2;
            }
            return GetLetterByNumber(ichar);
        }

        protected static string GetLetterByNumber(long number)
        {
            if ((number >= 45217) && (number <= 45252)) 
             {  
                return "A";  
             }  

             else if ((number >= 45253) && (number <= 45760))  

             {  

                 return "B";  

             }  

             else if ((number >= 45761) && (number <= 46317))  

             {  

                 return "C";  

            }  

            else if ((number >= 46318) && (number <= 46825))  

            {  

                return "D";  

            }  

            else if ((number >= 46826) && (number <= 47009))  

             {  

                return "E";  

            }  

             else if ((number >= 47010) && (number <= 47296))  

             {  

                return "F";  

            }  

            else if ((number >= 47297) && (number <= 47613))  

            {  

                return "G";  

            }  

            else if ((number >= 47614) && (number <= 48118))  

            {  

                 return "H";  

            }  

            else if ((number >= 48119) && (number <= 49061))  

            {  

                return "J";  

           }  

             else if ((number >= 49062) && (number <= 49323))  

            {  

                return "K";  

            }  

             else if ((number >= 49324) && (number <= 49895))  

            {  

                 return "L";  

            }  

             else if ((number >= 49896) && (number <= 50370))  

             {  

                 return "M";  

            }  


            else if ((number >= 50371) && (number <= 50613))  

             {  

                return "N";  

            }  

            else if ((number >= 50614) && (number <= 50621))  

             {  

                 return "O";  

             }  

             else if ((number >= 50622) && (number <= 50905))  

             {  

                 return "P";  

            }  

            else if ((number >= 50906) && (number <= 51386))  

            {  

                return "Q";  

            }  

            else if ((number >= 51387) && (number <= 51445))  

             {  

                return "R";  

             }  

             else if ((number >= 51446) && (number <= 52217))  

            {  

                 return "S";  

             }  

             else if ((number >= 52218) && (number <= 52697))  

            {  

                 return "T";  

             }  

            else if ((number >= 52698) && (number <= 52979))  

             {  

                return "W";  

             }  

             else if ((number >= 52980) && (number <= 53688))  

            {  

                 return "X";  

             }  

            else if ((number >= 53689) && (number <= 54480))  

             {  

                return "Y";  

             }  

             else if ((number >= 54481) && (number <= 55289))  

             {  

                 return "Z";  

             }  

             else return ("");  

             }
    }
}
